<script>
	export default {
		data() {
			return { res: '', ismust_one: true };
		},
		onLoad() {
			// // #ifdef APP-PLUS
			// 	var icon = plus.nativeObj.View.getViewById("icon");
			// 	if (icon) {
			// 		setTimeout(function(){
			// 			icon.show();
			// 		},100)
			// 	}
			// // #endif
		},
		onShow: function() {  
			// #ifdef APP-PLUS
				var args= plus.runtime.arguments;
				if(args){
					var str = args.split('=')
					uni.navigateTo({
						url: '/pages/news/list2detail-detail?data="'+str[1]
					});
					// huatong://detailid=1
					// 处理args参数，如直达到某新页面等  
				}  
			// #endif
			
			// #ifdef APP-PLUS
			if (this.ismust_one) {
				this.contrast(this.res);
			}
			//#endif
		},
		onLaunch: function() {
			uni.setStorageSync('appstu', 1);
			this.select();
			// 风险巡查中转让任务使用
			uni.removeStorageSync('to_user');
			uni.removeStorageSync('task_mission_id');
		},
		methods:{
			contrast: function(res) {
				if (res == '') {
					return false;
				}
				let _this = this;
				let ismust = false;
				let hasnew = false;
				let version = '';
				plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
					version = wgtinfo.version;
					uni.setStorageSync('app_version', version);
					if (res.version !== version && res.is_must == 1) {
						ismust = true;
						hasnew = true;
					} else if (res.version !== version && res.is_must == 0) {
						hasnew = true;
						_this.ismust_one = false;
					}
					let downloadUrl = res.downloadUrl;
				// console.log('dasd======',res.version , version,res.is_must)
					if (hasnew) {
						if(ismust){
							uni.showModal({
								//提醒用户更新
								title: '更新提示',
								content: res.content,
								showCancel: false,
								success: res1 => {
									if (res1.confirm) {
										plus.runtime.openURL(downloadUrl);
									}else{
										plus.runtime.quit();
									}
								}
							});
						}else{
							uni.showModal({
								//提醒用户更新
								title: '更新提示',
								content: res.content,
								showCancel: true,
								success(res) {
									uni.showLoading()
									if(res.confirm){
										uni.downloadFile({
											url: downloadUrl,
											success: (downloadResult) => {
												uni.hideLoading()
												if (downloadResult.statusCode === 200) {  
													plus.runtime.install(downloadResult.tempFilePath, {  
														force: false  
													}, function() {  
														console.log('install success...');
														plus.runtime.restart();  
													}, function(e) {  
														console.error('install fail...');
													});  
												}  
											}  
										});
									}else{
										uni.hideLoading()
									}
								}
							});
						}
					}
				});
			},
			select: function() {
				//#ifdef APP-PLUS
				var _this = this
				/* 5+环境锁定屏幕方向 */
				plus.screen.lockOrientation('portrait-primary'); //锁定
				/* 5+环境升级提示 */
				var server = this.$API.verseionCheck; //检查更新地址
				var type = 1;
				plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
					if (plus.os.name === 'iOS') {
						type = 2
					}
					uni.request({
						url: server,
						data:{
							type:type//安卓 用1ios用2
						},
						success: res => {
							_this.res = res;
							_this.contrast(res.data.data);
						}
					});
				})
				//#endif
			}
		}
	}
</script>
<style>
/* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
	@import './common/uni.css';
	/* 以下样式用于 hello uni-app 演示所需 */
	page {
		background-color: #F4F5F6;
		height: 100%;
		font-size: 28upx;
		line-height: 1.8;
	}

	.uni-header-logo {
		padding: 30upx;
		text-align: center;
		margin-top: 10upx;
	}

	.uni-header-logo image {
		width: 140upx;
		height: 140upx;
	}

	.uni-hello-text {
		color: #7A7E83;
	}

	.uni-hello-addfile {
		text-align: center;
		line-height: 300upx;
		background: #FFF;
		padding: 50upx;
		margin-top: 10px;
		font-size: 38upx;
		color: #808080;
	}
	
	/*自定义头部*/
	.head{
		height: 88upx;
		background: #fff;
	}
	.head .left,
	.head .right{
		width: 140upx;
	}
	.head .left{
		text-align: left;
		padding-left: 10upx;
	}
	.head .center{
		font-size: 32upx;
		text-align: center;
		width: calc(100% - 280upx);
	}
	.head .right{
		text-align: right;
		padding-right: 20upx;
	}
	.head .right image{
		width: 44upx;
		height: 44upx;
		margin-top: 20upx;
	}
	
	/*公共布局*/
	.status_bar{
		width: 100%;
		height: var(--status-bar-height);
	}
	.flex-row{
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.flex-column{
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
	}
	
	.nodata{
		color: #999;
		text-align: center;
		padding: 40upx;
		font-size: 28upx;
	}
	
	.require{
		color: red;
		font-weight: bold;
	}
	
	/*表格*/
	.table{
		border-bottom: 2upx solid #D5D5D5;
	}
	.table .tr{
		border: 2upx solid #D5D5D5;
		border-bottom: none;
		display: flex;
		align-items: center;
	}
	.table .tr .td{
		height: 100%;
		padding: 10upx 20upx;
		text-align: left;
	}
	.table .tr .td:first-child{
		width: 220upx;
		box-sizing: border-box;
	}
	.table .tr .td:last-child{
		width: calc(100% - 220upx);
		border-left: 2upx solid #D5D5D5;
	}
	
	/*签名弹窗*/
	.popup-outter{
		background: #fff;
		padding: 10upx;
	}
	.popup-inner{
		background: #BFE9FF;
		border-radius: 10upx;
		padding: 0 20upx 20upx;
	}
	.popup-title{
		height: 80upx;
		line-height: 80upx;
		font-size: 32upx;
		text-align: center;
		position: relative;
	}
	.popup-title view{
		position: absolute;
		top: 14upx;
		right: 0;
	}
	.popup-title view image{
		width: 40upx;
		height: 40upx;
		margin-right: 8upx;
	}
	.popup-inner canvas{
		width: 100%;
		height: 400upx;
		background: #F0F0F0;
		border-radius: 10upx;
	}
	.popup-inner .btns{
		height: 100upx;
		line-height: 100upx;
		margin-top: 10upx;
		justify-content: center;
		padding: 0 !important;
	}
	.popup-inner .btns view{
		background: #fff;
		border-radius: 10upx;
		padding: 10upx 60upx;
		box-shadow: 0 4upx 6upx #999;
	}
	.popup-inner .btns view:first-child{
		margin-right: 60upx;
	}
	
	/*tab切换*/
	.head-tabs{
		height: 80upx;
		background: #fff;
		justify-content: space-around;
	}
	.head-tabs .tab{
		text-align: center;
		width: 50%;
		position: relative;
	}
	.head-tabs .tab.active{
		color: #157FC2;
		position: relative;
	}
	.head-tabs .tab.active::after{
		content: '';
		width: 80%;
		height: 6upx;
		background: #157FC2;
		position: absolute;
		bottom: -10upx;
		left: 10%;
	}
	.head-tabs .tab view{
		width: 30upx;
		height: 30upx;
		color: #fff;
		font-size: 20upx;
		text-align: center;
		line-height: 30upx;
		border-radius: 50%;
		background: #FF6E03;
		position: absolute;
		top: -4upx;
		right: -20upx;
	}
</style>